#include <boost/date_time/posix_time/posix_time.hpp>
#include <ctime>
#include <locale>

#include <quigon/basic/basic_utils.h>

using namespace std;
using namespace boost::posix_time;

namespace quigon
{

string status_str(int status_num)
{
	string res;
	if (status_num & Status::BACKGROUND)
		res += "<BACKGROUND>";
	if (status_num & Status::AFTERPULSE)
		res += "<AFTERPULSE>";
	if (status_num & Status::DISTANCE)
		res += "<DISTANCE>";
	if (status_num & Status::OVERLAP)
		res += "<OVERLAP>";
	if (status_num & Status::ENERGY)
		res += "<ENERGY>";
	if (status_num & Status::LC)
		res += "<LC>";
	if (status_num & Status::EX)
		res = "<EX>";   // extinction data, no need to mention everything above.
	if (status_num & Status::INVALID)
		res = "<INVALID>";	// invalid(maybe false data to fill the time gap
	return res;
}

void print_time(ostream& stream, const string& prefix)
{
	stream << prefix << second_clock::local_time() << endl;
}

void imbue(istream& stream, const string& format_str)
{
	time_input_facet* facet(new time_input_facet(format_str.c_str()));
	stream.imbue(locale(stream.getloc(), facet));
}

void imbue(ostream& stream, const string& format_str)
{
	time_facet* facet(new time_facet(format_str.c_str()));
	stream.imbue(locale(stream.getloc(), facet));
}

void imbue(iostream& stream, const string& format_str)
{	
	time_input_facet* i_facet(new time_input_facet(format_str.c_str()));
	stream.imbue(locale(stream.getloc(), i_facet));
	time_facet* facet(new time_facet(format_str.c_str()));
	stream.imbue(locale(stream.getloc(), facet));
}

}

